import 'dart:convert';

import 'package:flutter/material.dart';

import '../model/details.dart';
import '../service/service_method.dart';

class DetailsInfoProvide with ChangeNotifier {
  DetailsModel goodsInfo = null;

  //详情页tabbar
  bool isLeft = true;
  bool isRight = true;
  //tabnar切换
  changeLeftAndRight(String changeState){
    if(changeState=='left'){
      isLeft = true;
      isRight = false;
    }else{
      isLeft = false;
      isRight = true;
    }
    notifyListeners();
  }


  //从后台获取商品信息
  getGoodsInfo(String id) async{
    var formData = {
      'goodId': id,
    };
    await request('getGoodDetailById', formData: formData).then((val) {
      var responseData = json.decode(val.toString());
      print(responseData);
      //转换为对象
      goodsInfo = DetailsModel.fromJson(responseData);

      notifyListeners();
    });
  }
}
